package com.wechat.utils.kit;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2016/8/19.
 * 客户端类型工具类
 * 根据 user agent string 来判断出客户端的浏览器以及平台等信息
 */
public final class BrowserKit {

    /**
     * 判断是否是移动设备
     * @param request
     * @return
     */
    public static boolean isMoblie(HttpServletRequest request) {
        boolean isMoblie = false;
        if (request.getHeader("User-Agent") != null) {
            if (request.getHeader("User-Agent").toLowerCase().contains("mobile")){
                isMoblie= true;
            }
        }

        return isMoblie;
    }

    /**
     * 判断是否是微信客户端
     * @param request
     * @return
     */
    public static  boolean isWechat(HttpServletRequest request){
        if (StrKit.notNull(request.getHeader("User-Agent"))){
            if (request.getHeader("User-Agent").toLowerCase().contains("micromessenger")){
                return true;
            }
        }

        return false;
    }


    /**
     * 判断是否是苹果设备
     * @param request
     * @return
     */
    public static  boolean isIPhone(HttpServletRequest request){
        if (StrKit.notNull(request.getHeader("User-Agent"))){
            if (request.getHeader("User-Agent").toLowerCase().contains("iphone")){
                return true;
            }
        }

        return false;
    }

    /**
     * 判断是否是Android设备
     * @param request
     * @return
     */
    public static  boolean isAdroid(HttpServletRequest request){
        if (StrKit.notNull(request.getHeader("User-Agent"))){
            if (request.getHeader("User-Agent").toLowerCase().contains("android")){
                return true;
            }
        }

        return false;
    }
}
